package com.gitee.hermer.engine.jars.dependent.logging.filter;

import org.slf4j.MDC;

import com.gitee.hermer.boot.jee.commons.utils.StringUtils;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.dependent.logging.layouts.SampleModelClassicConverter;

import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.filter.AbstractMatcherFilter;
import ch.qos.logback.core.spi.FilterReply;

public class SampleModelFilter  extends AbstractMatcherFilter<ILoggingEvent> {

	@Override
	public FilterReply decide(ILoggingEvent event) {

		String appInfo = SampleModelClassicConverter.getModelAppInfo();
		if(StringUtils.isNotBlank(appInfo)){
			if(StringUtils.defaultIfEmpty(MDC.get(EngineConstant.MODEL_LOGGING_MDC_LOG_FILE_PARAMS), "").indexOf(appInfo) == -1)
				MDC.put(EngineConstant.MODEL_LOGGING_MDC_LOG_FILE_PARAMS, StringUtils.format(EngineConstant.MODEL_LOGGING_LOG_FILE_SUFFIX,appInfo));
			return onMatch;
		}else{
			return onMismatch;
		}
	}

}
